package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.douluodalu.DouLuoDaLuModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_TEAM_CREATE_FROM_CROSS,desc = "创建队伍")
public class DouLuoDaLuCreateTeamCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuCreateTeamRespMsg respMsg = DouLuoDaLuProto.DouLuoDaLuCreateTeamRespMsg.parseFrom(packet.getBytes());
        ret = respMsg.getRet();
        DouLuoDaLuModule douLuoDaLuModule = player.getModule(DouLuoDaLuModule.class);
        Property property = douLuoDaLuModule.createTeamProperty;
        if(douLuoDaLuModule.createTeamProperty != null){
            player.getModule(PreReduceModule.class).restorePreReduce(douLuoDaLuModule.createTeamProperty);
            douLuoDaLuModule.createTeamProperty = null;
        }
        if(ret == 0){
            if(!respMsg.getIsFirstCreate()){
                player.getModule(CurrencyModule.class).removeCurrency(property, eLogMoneyType.DouLuoDaLuActivity, eLogMoneyType.DouLuoDaLuCreatTeamCost);
            }
        }
        player.sendPacket(ClientProtocol.U_DOU_LUO_DA_LU_TEAM_CREATE, respMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
